<?php
/**
 * Created by lzl
 * Date: 2021 2021/9/23
 * Time: 13:08
 */
namespace App\Forms;

use App\Models\Config;

class ConfigForms extends BaseForm
{
    public function getConfig()
    {
        return Config::get();
    }


    /**
     * @param $key
     * @return Config|\Illuminate\Database\Eloquent\Model|object|null
     */
    public function getDetail($key)
    {
        return Config::where('key', $key)->first();
    }

    /**
     * @param $validated
     * @return bool
     */
    public function updateConfig($validated)
    {

        if(is_array($validated) && count($validated)){
            foreach ($validated as $key => $value){
                Config::where('key', $key)->update(['value' => $value]);
            }
        }

        return true;
    }
}